<template>

	<view class="searchlist-container">
		<!-- 搜索关键词展示 -->
		<view class="search-keyword">
			<text>搜索结果: {{keyword}}</text>
		</view>


		<!-- 商品列表区域 -->

		<view class="product-section">
			<view class="section-title">
				<text>找到 {{arr.length}} 个商品</text>
			</view>
			<view class="product-list">
				<view class="product-item" v-for="iitem in arr" :key="iitem.proid" @click="golist(iitem)">
					<view class="product-image">
						<image :src="iitem.img2" mode="aspectFill"></image>
					</view>
					<view class="product-info">
						<text lines="2" class="product-name">{{iitem.proname}}</text>
						<view class="product-price-sales">
							<view class="product-price">
								<text class="price-text">¥{{iitem.originprice}}</text>
							</view>
							<text class="sales-text">已售{{iitem.sales}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"
	let keyword = ref("");
	let arr = ref([])
	onLoad((option) => {
		console.log(option.str)
		keyword = option.str
		searchlist()
	})
	const searchlist = () => {
		uni.request({
			url: "https://www.xuzhixiang.top:30001/api/pro/search",
			method: "GET",
			data: {
				count: 1,
				limitNum: 10,
				keyword
			},
			success: (e) => {
				console.log(e.data.data)
				arr.value = e.data.data
			}
		})
	}

	function golist(item) {
		console.log(item.proid)
		uni.navigateTo({
			url: "/pages/listxq/listxq?proid=" + item.proid
		})
	}
</script>

<style>
	/* 容器样式 */
	.searchlist-container {
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 搜索关键词样式 */
	.search-keyword {
		padding: 20rpx;
		background-color: #fff;
		border-radius: 8rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;
		color: #333;
	}

	/* 加载状态容器样式 */
	.loading-container {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 200rpx 0;
	}

	/* 加载动画样式 */
	.loading {
		width: 50rpx;
		height: 50rpx;
		border: 5rpx solid #eee;
		border-top-color: #e64340;
		border-radius: 50%;
		animation: spin 1s linear infinite;
		margin-bottom: 20rpx;
	}

	@keyframes spin {
		to {
			transform: rotate(360deg);
		}
	}

	/* 加载文本样式 */
	.loading-text {
		font-size: 28rpx;
		color: #999;
	}

	/* 空状态容器样式 */
	.empty-container {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 200rpx 0;
	}

	/* 空状态图片样式 */
	.empty-image {
		width: 200rpx;
		height: 200rpx;
		margin-bottom: 30rpx;
	}

	/* 空状态文本样式 */
	.empty-text {
		font-size: 28rpx;
		color: #999;
		margin-bottom: 30rpx;
	}

	/* 空状态按钮样式 */
	.empty-btn {
		width: 200rpx;
		height: 60rpx;
		line-height: 60rpx;
		background-color: #fff;
		color: #e64340;
		font-size: 28rpx;
		border-radius: 6rpx;
		border: 1rpx solid #e64340;
		padding: 0;
	}

	/* 商品列表样式 */
	.product-section {
		background-color: #fff;
		margin-bottom: 20rpx;
		padding-bottom: 20rpx;
	}

	.section-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		border-bottom: 1rpx solid #eee;
	}

	.product-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 10rpx;
	}

	.product-item {
		width: 48%;
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 8rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.product-image {
		width: 100%;
		height: 300rpx;
		overflow: hidden;
	}

	.product-image image {
		width: 100%;
		height: 100%;
	}

	.product-info {
		padding: 16rpx;
	}

	.product-name {
		font-size: 28rpx;
		color: #333;
		margin-bottom: 10rpx;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	.product-price-sales {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.product-price {
		color: #e64340;
		font-size: 32rpx;
		font-weight: bold;
	}

	.sales-text {
		font-size: 24rpx;
		color: #999;
	}

	/* 以下样式已在上方定义，此处为重复代码已删除 */

	.product-image image {
		width: 100%;
		height: 100%;
		transition: transform 0.3s;
	}

	.product-image:hover image {
		transform: scale(1.05);
	}

	.product-info {
		padding: 15rpx;
	}

	.product-name {
		font-size: 28rpx;
		color: #333;
		margin-bottom: 10rpx;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	.product-stock {
		font-size: 22rpx;
		color: #999;
		margin-bottom: 10rpx;
	}

	.product-price-sales {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.product-price {
		color: #e60012;
		font-weight: bold;
	}

	.price-text {
		font-size: 30rpx;
	}

	.sales-text {
		font-size: 22rpx;
		color: #999;
	}
</style>